//
//  YZPublishCommunityFunctionCell.m
//  VET
//
//  Created by YZ on 2018/7/10.
//  Copyright © 2018年 YZ. All rights reserved.
//

#import "YZPublishCommunityFunctionCell.h"

@interface YZPublishCommunityFunctionCell()

@property (nonatomic, strong) UIImageView *logoImgView;

@property (nonatomic, strong) UILabel *titleLb;

@property (nonatomic, strong) UILabel *selectLb;

@property (nonatomic, strong) UIView *sepline;

@property (nonatomic, strong) UIImageView *transferImgView;

@end

@implementation YZPublishCommunityFunctionCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        self.layer.masksToBounds = YES;
        [self.contentView addSubview:self.logoImgView];
        [self.contentView addSubview:self.titleLb];
        [self.contentView addSubview:self.selectLb];
        [self.contentView addSubview:self.transferImgView];
        [self.contentView addSubview:self.sepline];
        
        [self makeContraints];
    }
    return self;
}

- (void)makeContraints
{
    [self.logoImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.size.mas_equalTo(CGSizeMake(kCurrentDeviceNum(15), kCurrentDeviceNum(19)));
        make.left.mas_equalTo(20);
    }];
    
    [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.left.equalTo(self.logoImgView.mas_right).offset(15);
        make.width.mas_lessThanOrEqualTo(200);
    }];
    
    [self.selectLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.right.equalTo(self.transferImgView.mas_left).offset(-kCurrentDeviceNum(5));
        make.width.mas_lessThanOrEqualTo(200);
    }];
    
    [self.transferImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.right.equalTo(self.contentView.mas_right).offset(-kCurrentDeviceNum(10));
        make.size.mas_equalTo(CGSizeMake(kCurrentDeviceNum(16), kCurrentDeviceNum(16)));
    }];
    
    [self.sepline mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(kCurrentDeviceNum(18));
        make.right.equalTo(self.contentView.mas_right).offset(-kCurrentDeviceNum(18));
        make.bottom.mas_equalTo(0);
        make.height.mas_equalTo(kCurrentDeviceNum(0.5));
    }];
}

- (void)setNormalStyle:(BOOL)normal
{
    if (self.model.functionType == YZCommunityFunctionTypeLocation) {
        self.titleLb.textColor = normal?kColorWithHex(0x393939):kColorWithHex(0x32BE60);
        self.transferImgView.hidden = normal?NO:YES;
    }else
    {
        self.transferImgView.hidden = NO;
        self.titleLb.textColor = normal?kColorWithHex(0x393939):kColorWithHex(0x32BE60);
        self.selectLb.textColor = normal?kColorWithHex(0x393939):kColorWithHex(0x32BE60);
    }
}

#pragma mark -- setters && getters

- (UIImageView *)logoImgView
{
    if(!_logoImgView){
        _logoImgView = [UIImageView new];
    }
    return _logoImgView;
}

- (UILabel *)titleLb
{
    if(!_titleLb){
        _titleLb = [UILabel new];
        _titleLb.textAlignment = NSTextAlignmentCenter;
        _titleLb.font = kCurrentDeviceFont(16);
    }
    return _titleLb;
}

- (UILabel *)selectLb
{
    if(!_selectLb){
        _selectLb = [UILabel new];
        _selectLb.textAlignment = NSTextAlignmentRight;
        _selectLb.textColor = kColorWithHex(0x9B9B9B);
        _selectLb.font = kCurrentDeviceFont(16);
    }
    return _selectLb;
}

- (UIImageView *)transferImgView
{
    if(!_transferImgView){
        _transferImgView = [UIImageView new];
    }
    return _transferImgView;
}

- (void)setModel:(YZPublishCommunityFunctionModel *)model
{
    _model = model;
    [self setNormalStyle:model.normal];
    self.logoImgView.image = [UIImage imageNamed:model.logo];
    self.titleLb.text = model.title;
    self.selectLb.text = model.selectTitle;
    self.transferImgView.image = [UIImage imageNamed:model.transferImg];
}

@end
